﻿/*
创建人：longb
日期：2022-06-20
描述：试车返回单打印js
*/
var page = {
    pagetotal: 0,
    pageSize: 20,
    pageNumber: 1,
    id: getParam("id"), //返回单ID
    rootPath: getRootPath(), //网站根路径
    ajaxUrl: getRootPath() + "/Ashx/ZsHandler/ZSTestRunReturnBillHandler.ashx",
    //初始化页面
    init: function () {
        page.GetReturnBillData();
        page.GetTRReturnCFBillData();
        page.GetTRReturnUFBillData();
    },
    //查询试车通知单信息
    GetReturnBillData: function () {
        var data = {ZSTESTRUNRETURNBILLID: page.id };
        var param = {
            action: "GetReturnBillDataByID",
            pageSize: 1,
            pageNumber: 1,
            data: JSON.stringify([data])
        };
        page.post(param, function (res) {
            console.info(res.DBTable);
        });
    },
    //查询成附件
    GetTRReturnCFBillData: function () {
        var param = {
            action: "GetTRReturnCFBill",
            ZSTESTRUNRETURNBILLID: page.id
        };
        var CFJhtml = "";
        page.post(param, function (res) {
            $.each(res.DBTable, function (index, item) {
                CFJhtml += '<tr><td style="height:30px">' + item.DEPENDTYPE + '</td><td>' + item.PREBATCHNO + '</td><td>' + item.AFTERBATCHNO + '</td><td colspan="2">' + item.PREWORKMINS + '</td><td colspan="3">' + item.CHANGEREASON + '</td></tr>'
            });
            var rowspan = res.DBTable.length + 2;
            if (CFJhtml == "") {
                rowspan = 4;
                CFJhtml = '<tr><td style="height:30px"></td><td></td><td></td><td colspan="2"></td><td colspan="3"></td></tr><tr><td style="height:30px"></td><td></td><td></td><td colspan="2"></td><td colspan="3"></td></tr>';
            }
            $("#CFJrowspan").attr("rowspan", rowspan);
            $("#CFJ").after(CFJhtml);
        });

    },
    //查询未排除的故障
    GetTRReturnUFBillData: function () {
        var param = {
            action: "GetTRReturnUFBillData",
            ZSTESTRUNRETURNBILLID: page.id
        };
        page.post(param, function (res) {
            var PCFFhtml = "";
            var PCGZhtml = "";
            var rowspan = res.DBTable.length + res.DBTable.length + 4;
            $.each(res.DBTable, function (index, item) {
                PCGZhtml += '<tr><td style="height:30px">' + item.SERIALNUMBER + '</td><td >' + item.FAULTTYPE + '</td><td colspan="6">' + item.FAULTPERFORM + '</td></tr>';
                PCFFhtml += ' <tr><td style="height:30px">' + item.SERIALNUMBER + '</td><td colspan="7">' + (item.EXCLUDEMETHODS == null ? "" : item.EXCLUDEMETHODS) + '</td></tr>'
            });
            $("#PCGZrowspan").attr("rowspan", rowspan);
            $("#PCGZ").after(PCGZhtml);
            $("#PCFF").after(PCFFhtml);
        });
    },
    //post数据
    post: function (param, callback) {
        $.ajax({
            type: "Post",
            url: page.ajaxUrl,
            data: param,
            cashe: false,
            async: true,
            dataType: "json",
            beforeSend: function () {
                $.messager.progress({ text: '', msg: '处理中...' });
            },
            success: function (data) {
                $.messager.progress('close');
                callback(data);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.messager.progress('close');
                displayMessage(XMLHttpRequest.responseText, false);
            }
        });
    }
}
$(function () {
    page.init();
});